#include "stdafx.h"
#include "Graph.h"

namespace GraphTools
{
	EdmondsEdge::EdmondsEdge()
		: elems(3)
	{
		elems[0] = -1;
		elems[1] = -1;
		elems[2] = -1;
	}

	EdmondsEdge::EdmondsEdge(Graph g, ptr<Edge> e)
		: elems(3)
	{
		auto terminals = e->GetTerminals();
		int start = g.IndexOf(terminals.front());
		int end = g.IndexOf(terminals.back());
		elems[0] = start;
		elems[1] = end;
		elems[2] = e->GetWeight();
	}

	EdmondsEdge::EdmondsEdge(int start, int end, int w)
		: elems(3)
	{
		if (start == end)
		{
			elems[0] = start;
			elems[1] = end;
			elems[2] = w;
		}
		if (start < end){
		elems[0] = start;
		elems[1] = end;}
		else
		{
			elems[0] = end;
		elems[1] = start;
		}

		elems[2] = w;
	}

	int EdmondsEdge::operator[] (int i)
	{
		return this->elems[i];
	}

	bool EdmondsEdge::isEquivalent(int start, int end)
	{
		return
			start == this->elems[0] && end == this->elems[1] ||
			start == this->elems[1] && end == this->elems[0];
	}
	
	bool EdmondsEdge::isEquivalent(int start, int end, int weight)
	{
		return
			start == this->elems[0] && end == this->elems[1] && weight == this->elems[2] ||
			start == this->elems[1] && end == this->elems[0] && weight == this->elems[2];
	}
	string convertInt(int number)
	{
		if (number == 0)
			return "0";
		string temp="";
		string returnvalue="";
		while (number>0)
		{
			temp+=number%10+48;
			number/=10;
		}
		for (int i=0;i<temp.length();i++)
			returnvalue+=temp[temp.length()-i-1];
		return returnvalue;
	}
	string EdmondsEdge::ToString()
	{
		string res = "";
		res += convertInt(elems[0]) + "\t" + convertInt(elems[1]) + "\t" + convertInt(elems[2]) + "\n";
		return res;
	}
}
